#include "Audio.h"
#include "Error.h"
#include "Log.h"

namespace Engine
{
	bool Audio::Initialize()
	{
		Log("****Initializing Audio****");
		m_audioEngine = irrklang::createIrrKlangDevice(irrklang::ESOD_AUTO_DETECT, 61, (const char*)0, "1.3.0");

		if(!m_audioEngine)
		{
			Error("Unable to initialize Audio");
			return false;
		}
		Log("Audio initialized");
		Log(" ");
		return true;
	}

	void Audio::SetListener(const Vec3& pos, const Vec3& lookDir, const Vec3& vel, const Vec3& upVec)
	{
		if(m_audioEngine) m_audioEngine ->setListenerPosition(irrklang::vec3df(pos.x, pos.y, pos.z), 
															  irrklang::vec3df(lookDir.x, lookDir.y, lookDir.z),
															  irrklang::vec3df(vel.x, vel.y, vel.z),
															  irrklang::vec3df(upVec.x, upVec.y, upVec.z));
	}

	void Audio::PauseAllSounds() 
	{
		if (m_audioEngine)
		{
			m_audioEngine ->setAllSoundsPaused(true);
		}
	}

	Audio::~Audio()
	{
		if(m_audioEngine)
			m_audioEngine ->drop();
	}
}
 